
app.controller('subGridCtrl', ['$scope', '$http', function SubGridController($scope, $http){
	
	console.log('--------$scope.gridId--------', $scope.gridId);
	var gridId = $scope.gridId;
	
	/*
	 * 复选框回调
	 */
	$scope.checkbox.afterSelectDatas = function(rowsSelected) {
		console.log('--------YsSubGrid--------', rowsSelected);
		// 处理多选
		if(gridId == 3) { // 物料出库单明细
			$scope.getDataAfterCheckbox3(rowsSelected);
		} else if(gridId == 4) { // 员工工资申请表
			$scope.getDataAfterCheckbox4(rowsSelected);
		}  else if(gridId == 7) { // 物料借用单
			$scope.getDataAfterCheckbox7(rowsSelected);
		} else if(gridId == 8) { // 物料转移单明细
			$scope.getDataAfterCheckbox8(rowsSelected);
		} else if(gridId == 9) { // 员工月度绩效申报
			$scope.getDataAfterCheckbox9(rowsSelected);
		} else if(gridId == 10) { // 物料入库单详情
			$scope.getDataAfterCheckbox10(rowsSelected);
		} else if(gridId == 12) { // 社保付款单
			$scope.getDataAfterCheckbox12(rowsSelected);
		} else if(gridId == 13) { // 公积金付款单
			$scope.getDataAfterCheckbox13(rowsSelected);
		}else if(gridId == 17) { // 预支账户报销单
			$scope.getDataAfterCheckbox17(rowsSelected);
		} else if(gridId == 19) { // 应付账户支付
			$scope.getDataAfterCheckbox19(rowsSelected);
		} else if(gridId == 20) { // 预约调拨详情
			$scope.getDataAfterCheckbox20(rowsSelected);
		} else if(gridId == 21) { // 资金登记单
			$scope.getDataAfterCheckbox21(rowsSelected);
		} else if(gridId == 23) { // 预付款认领单
			$scope.getDataAfterCheckbox23(rowsSelected);
		} else if(gridId == 24) { // 亚马逊店铺管理
			$scope.getDataAfterCheckbox24(rowsSelected);
		} else if(gridId == 25) { // 资金认领单
			$scope.getDataAfterCheckbox25(rowsSelected);
		} else if(gridId == 27) { // VAT申报
			$scope.getDataAfterCheckbox27(rowsSelected);
		} else if(gridId == 28) { // 万里汇提款单
			$scope.getDataAfterCheckbox28(rowsSelected);
		} else if(gridId == 30) { // 万里汇CNY付款单
			$scope.getDataAfterCheckbox30(rowsSelected);
		} else if(gridId == 31) { // 预付款退回申请列表
			$scope.getDataAfterCheckbox31(rowsSelected);
		} else if(gridId == 32) { // VAT申报详情
			$scope.getDataAfterCheckbox32(rowsSelected);
		} else if(gridId == 34) { // 万里汇预付款入账单
			$scope.getDataAfterCheckbox34(rowsSelected);
		} else if(gridId == 35) { // 万里汇外币付款单
			$scope.getDataAfterCheckbox35(rowsSelected);
		} else if(gridId == 36) { // 万里汇预付款对账单
			$scope.getDataAfterCheckbox36(rowsSelected);
		} else if(gridId == 33) { // 万里汇补账单
			$scope.getDataAfterCheckbox33(rowsSelected);
		} else if(gridId == 37) { // 财务工资小计部门维护表
			$scope.getDataAfterCheckbox37(rowsSelected);
		} else if(gridId == 38) { // 预约调拨取消单
			$scope.getDataAfterCheckbox38(rowsSelected);
		} else if(gridId == 39) { // 手工分配单
			$scope.getDataAfterCheckbox39(rowsSelected);
		} else if(gridId == 43) { // 财务交易类型子表
			$scope.getDataAfterCheckbox43(rowsSelected);
		}
	}
	$scope.getDataAfterCheckbox3 = function (rowsSelected) {
		for (var i = 0; i < rowsSelected.length; i++) {
			var row = rowsSelected[i];
			$scope.subGrid.sonlist.push({
				num: 0,
				remark: '',
				stockInImg: row.stockInImg,
				stockInPrice: row.stockInPrice,
				materialCode: row.materialCode,
				materialRemark: row.materialRemark,
				stockNum: row.num,
				stockId: row.id,
				bidStockIn: row.bidStockIn,
				createTime: row.createTime,
				stockRemark: row.remark,
				orgName: row.orgName,
				companyVname: row.companyVname,
				orgHeadUserId: row.orgHeadUserId,
				stockDays: row.stockDays
			});
		}
	}
	$scope.getDataAfterCheckbox4 = function (rowsSelected) {
		if($scope.subGrid.sonlist != 0){
			let newall=[]
			let endData = [];
			var isdata=false
			for (let i = 0; i < rowsSelected.length; i++) {
				var isdata=false
				if (newall.indexOf(rowsSelected[i].userPaySlipidid) === -1) {
					for (var n = 0; n < $scope.subGrid.sonlist.length; n++) {
						if (newall.indexOf(rowsSelected[i].userPaySlipidid) === -1) {
							if(rowsSelected[i].userPaySlipidid== $scope.subGrid.sonlist[n].userPaySlipidid){
								isdata=true
								endData.push($scope.subGrid.sonlist[n]);
								newall.push($scope.subGrid.sonlist[n].userPaySlipidid);
							}
						}
					}
					if(!isdata){
						endData.push(rowsSelected[i]);
						newall.push(rowsSelected[i].userPaySlipidid);
					}
				}
			}
			$scope.subGrid.sonlist = endData
		}else{
			$scope.subGrid.sonlist = rowsSelected
		}
		//计算逻辑
		var wagesPay = 0;
		var healthCompany = 0;
		var societyCompany = 0;
		var needPaySlip = 0;
		var personalTax = 0;
		var realityPaySlip = 0;
		var accumulationFundCompany = 0;
		for (var n = 0; n < $scope.subGrid.sonlist.length; n++) {
			wagesPay = wagesPay + Number($scope.subGrid.sonlist[n].wagesPay)
			healthCompany = healthCompany + Number($scope.subGrid.sonlist[n].healthCompany)
			societyCompany = societyCompany + Number($scope.subGrid.sonlist[n].retirementCompany)+ Number($scope.subGrid.sonlist[n].loseWorkCompany)+ Number($scope.subGrid.sonlist[n].injuryCompany)
			needPaySlip = needPaySlip + Number($scope.subGrid.sonlist[n].needPaySlip)
			personalTax = personalTax + Number($scope.subGrid.sonlist[n].personalTax)
			realityPaySlip = realityPaySlip + Number($scope.subGrid.sonlist[n].realityPaySlip)
			accumulationFundCompany = accumulationFundCompany + Number($scope.subGrid.sonlist[n].accumulationFundCompany)
		}
		if ($scope.subGrid.sonlist.length != 0){
			$scope.valueMap['orgName'] = $scope.subGrid.sonlist[0].orgName;
			$scope.valueMap['wagesPay'] = $scope.toFixed(wagesPay,2);
			$scope.valueMap['healthCompany'] = $scope.toFixed(healthCompany,2);
			$scope.valueMap['societyCompany'] = $scope.toFixed(societyCompany,2);
			$scope.valueMap['needPaySlip'] = $scope.toFixed(needPaySlip,2);
			$scope.valueMap['personalTax'] = $scope.toFixed(personalTax,2);
			$scope.valueMap['realityPaySlip'] = $scope.toFixed(realityPaySlip,2);
			$scope.valueMap['accumulationFundCompany'] = $scope.toFixed(accumulationFundCompany,2);
			$scope.valueMap['orgId'] = $scope.subGrid.sonlist[0].orgId;
			$scope.valueMap['pointMonth'] = $scope.subGrid.sonlist[0].pointMonth;
		}
	}
	$scope.getDataAfterCheckbox7 = function (rowsSelected) {
		for (var i = 0; i < rowsSelected.length; i++) {
			var row = rowsSelected[i];
			$scope.subGrid.sonlist.push({
				stockId: row.id,
				remark: '',
				img: row.img,
				materialCode: row.materialCode,
				materialName: row.materialName,
				materialRemark: row.materialRemark,
				stockNum: row.numAll,
				stockRemark: row.stockRemark,
				num: '',
				price: row.price,
				bidStockIn: row.bidStockIn,
				companyVname: row.companyVname,
				stockInDay: row.stockInDay,
				stockInDays: row.stockInDays,
				numBorrowed: row.numBorrowed
			});
		}
	}
	$scope.getDataAfterCheckbox8 = function (rowsSelected) {
		for (var i = 0; i < rowsSelected.length; i++) {
			var row = rowsSelected[i];
			$scope.subGrid.sonlist.push({
				num: 0,
				remark: '',
				stockId: row.id,
				numStock: row.num,
				numBorrowed: row.numBorrowed,
				orgHeadUserId: row.orgHeadUserId,
				orgName: row.orgName,
				companyVname: row.companyVname,
				storageDay: row.storageDay,
				storageTime: row.storageTime,
				bidStockIn: row.bidStockIn,
				price: row.price,
				quantityBorrowed: row.quantityBorrowed,
				inventoryQuantity: row.inventoryQuantity,
				materialRemark: row.materialRemark,
				materialName: row.materialName,
				materialCode: row.materialCode,
				img: row.stockInImg,
				remarks: '',
				borrowingDepartment: row.borrowingDepartment,
				borrowers: row.borrowers
			});
		}
	}
	$scope.getDataAfterCheckbox9 = function (rowsSelected) {//员工月度绩效申报
		for (var i = 0; i < rowsSelected.length; i++) {
			var obj = rowsSelected[i];
			var rowCurrent = {};
			rowCurrent.id = null;
			rowCurrent.monthPerformanceId = obj.id;

			rowCurrent.pointMonth = obj.pointMonth;//评定年月
			rowCurrent.userName = obj.userName;//工号/姓名
			rowCurrent.userState = obj.userState;//员工状态
			rowCurrent.deptName = obj.deptName;//部门
			rowCurrent.orgName = obj.orgName;//所属公司
			rowCurrent.rank = obj.rank;//岗位职级
			rowCurrent.type = obj.type;//岗位工种

			rowCurrent.hrPerformancePoint = 0.00;//人事绩效评分
			rowCurrent.hrPerformanceContent = '';//人事绩效内容
			rowCurrent.jobBonus = obj.jobBonus?obj.jobBonus:0.00;//岗位提奖
			rowCurrent.jobBonusExplain = obj.jobBonusExplain?obj.jobBonusExplain:'';//岗位提奖说明
			//过滤已选择的
			if($scope.subGrid.sonlist!=null && $scope.subGrid.sonlist.length>0){
				var isChoosed = false;
				for (var j = 0; j < $scope.subGrid.sonlist.length; j++) {
					if($scope.subGrid.sonlist[j].monthPerformanceId == obj.id){
						isChoosed = true;
					}
				}
			}
			if(!isChoosed){
				$scope.subGrid.sonlist.push(rowCurrent);
			}
		}
	}
	$scope.getDataAfterCheckbox10 = function (rowsSelected) {
		for (var i = 0; i < rowsSelected.length; i++) {
			var row = rowsSelected[i];
			$scope.subGrid.sonlist.push({
				num: '',
				price: '',
				materialCode: row.code,
				materialName: row.name,
				materialRemark: row.remark,
				remark: ''
			});
		}
	}

	$scope.getDataAfterCheckbox12 = function (rowsSelected) {
		var t = this;
		if($scope.subGrid.sonlist != 0){
			let newall=[]
			let endData = [];
			var isdata=false
			for (let i = 0; i < rowsSelected.length; i++) {
				var isdata=false
				if (newall.indexOf(rowsSelected[i].userMonthPerformanceId) === -1) {
					for (let n = 0; n < $scope.subGrid.sonlist.length; n++) {
						if (newall.indexOf(rowsSelected[i].userMonthPerformanceId) === -1) {
							if(rowsSelected[i].userMonthPerformanceId==$scope.subGrid.sonlist[n].userMonthPerformanceId){
								isdata=true
								endData.push($scope.subGrid.sonlist[n]);
								newall.push($scope.subGrid.sonlist[n].userMonthPerformanceId);
							}
						}
					}
					if(!isdata){
						endData.push(rowsSelected[i]);
						newall.push(rowsSelected[i].userMonthPerformanceId);
					}
				}
			}
			$scope.subGrid.sonlist = endData
		}else{
			$scope.subGrid.sonlist = rowsSelected
		}
		//计算逻辑
		var societyCompany = 0;
		var societyPersonal = 0;
		var orgName = "";
		for (let n = 0; n < $scope.subGrid.sonlist.length; n++) {
			orgName = $scope.subGrid.sonlist[n].orgName
			societyCompany = societyCompany + Number($scope.subGrid.sonlist[n].retirementCompany)+ Number($scope.subGrid.sonlist[n].loseWorkCompany)+ Number($scope.subGrid.sonlist[n].injuryCompany)
			societyPersonal = societyPersonal + Number($scope.subGrid.sonlist[n].retirementPersonal)+ Number($scope.subGrid.sonlist[n].loseWorkPersonal)
		}
		if ($scope.subGrid.sonlist.length != 0){
			$scope.valueMap['orgName'] = orgName;
			$scope.valueMap['societyCompany'] = societyCompany;
			$scope.valueMap['societyPersonal'] = societyPersonal;
			$scope.valueMap['societyTol'] = societyCompany+societyPersonal;
		}
	}
	$scope.getDataAfterCheckbox13 = function (rowsSelected) {
		if($scope.subGrid.sonlist != 0){
			let newall=[]
			let endData = [];
			var isdata=false
			for (let i = 0; i < rowsSelected.length; i++) {
				var isdata=false
				if (newall.indexOf(rowsSelected[i].userMonthPerformanceId) === -1) {
					for (let n = 0; n < $scope.subGrid.sonlist.length; n++) {
						if (newall.indexOf(rowsSelected[i].userMonthPerformanceId) === -1) {
							if(rowsSelected[i].userMonthPerformanceId==$scope.subGrid.sonlist[n].userMonthPerformanceId){
								isdata=true
								endData.push($scope.subGrid.sonlist[n]);
								newall.push($scope.subGrid.sonlist[n].userMonthPerformanceId);
							}
						}
					}
					if(!isdata){
						endData.push(rowsSelected[i]);
						newall.push(rowsSelected[i].userMonthPerformanceId);
					}
				}
			}
			$scope.subGrid.sonlist = endData
		}else{
			$scope.subGrid.sonlist = rowsSelected
		}
		//计算逻辑
		var accumulationFundCompany = 0;
		var accumulationFundPersonal = 0;
		var orgName = "";
		for (let n = 0; n < $scope.subGrid.sonlist.length; n++) {
			orgName = $scope.subGrid.sonlist[n].orgName
			accumulationFundCompany = accumulationFundCompany + Number($scope.subGrid.sonlist[n].accumulationFundCompany)
			accumulationFundPersonal = accumulationFundPersonal + Number($scope.subGrid.sonlist[n].accumulationFundPersonal)
		}
		if ($scope.subGrid.sonlist.length != 0){
			$scope.valueMap['orgName'] = orgName;
			$scope.valueMap['accumulationFundCompany'] = accumulationFundCompany;
			$scope.valueMap['accumulationFundPersonal'] = accumulationFundPersonal;
			$scope.valueMap['accumulationTol'] = accumulationFundCompany+accumulationFundPersonal;
		}
	}
	$scope.getDataAfterCheckbox17 = function (rowsSelected) {
		for (var i = 0; i < rowsSelected.length; i++) {
			var row = rowsSelected[i];
			$scope.subGrid.sonlist.push({
				reimbursementItemId: null,
				advanceAccountDetailId: row.id,
				id:row.id,
				createTime:row.createTime,
				companyName:row.companyName,
				advanceTypeName:row.advanceTypeName,
				vjylx:row.vjylx,
				detailName:row.detailName,
				unitPrice:row.unitPrice,
				quantity:row.quantity,
				totalPrice:row.totalPrice,
				remark:row.remark,
				userName:row.userName,
				deptName:row.deptName,
				annexFile:row.annexFile,
				detailType:row.detailType,
			});
		}
		var totalPriceByThis = 0;
		if($scope.subGrid.sonlist!=null && $scope.subGrid.sonlist.length>0){
			for(var i=0;i<$scope.subGrid.sonlist.length;i++){
				var totalPriceByItem = parseFloat($scope.subGrid.sonlist[i].totalPrice);
				if(totalPriceByItem){
					totalPriceByThis = totalPriceByThis+totalPriceByItem;
				}
			}
		}
		$scope.valueMap['totalPriceByThis'] = totalPriceByThis;
	}
	$scope.getDataAfterCheckbox19 = function (rowsSelected) {
		for (var i = 0; i < rowsSelected.length; i++) {
			var row = rowsSelected[i];
			$scope.subGrid.sonlist.push({
				needPayLedgerDetailId: row.id,
				createTime: row.createTime,
				needPayTypeCode: row.needPayTypeCode,
				needPayTypeName: row.needPayTypeName,
				vgsbm: row.vgsbm,
				vgsjc: row.vgsjc,
				vjylx: row.vjylx,
				detailName: row.detailName,
				costPrice: row.costPrice,
				quantity: row.quantity,
				totalPrice: row.totalPrice,
				materialRemark: row.remark,
				servicePrice: row.servicePrice,
				payedPrice: row.payedPrice,
				//unpayPrice: (row.costPrice * row.quantity - row.payedPrice),
				unpayPrice:0,
				amount: (row.costPrice * row.quantity).toFixed(2)
			});
		}
	}
	$scope.getDataAfterCheckbox20 = function (rowsSelected) {
    	var rows = [];
    	for (var i = 0; i < rowsSelected.length; i++) {
			var rowSelected = rowsSelected[i];

			var isAdd = true; // 根据现有存在，是否加新行
			for (var j = 0; j < $scope.subGrid.sonlist.length; j++) {
				if ($scope.subGrid.sonlist[j].productCode == rowSelected.code) {
					isAdd = false;
				}
			}

			var type = $scope.valueMap['type'];

			if (isAdd == true) {
				var row = {
					productCode: rowSelected.code,
					productName: rowSelected.name,
					singlePrice: rowSelected.priceIn,
					vgsbmFrom: type == 1 ? 'GS0641' : 'GS0877',
					vgsjcFrom: type == 1 ? '逸思精品' : '逸思库存'
				};
				$scope.subGrid.sonlist.push(row);
			}
		}
	}
	$scope.getDataAfterCheckbox21 = function (rowsSelected) {
		for (var i = 0; i < rowsSelected.length; i++) {
			var row = rowsSelected[i];
			var isAdd = true; // 根据现有存在，是否加新行
			for (var j = 0; j < $scope.subGrid.sonlist.length; j++) {

				if ($scope.subGrid.sonlist[j].vid == row.vid) {
					isAdd = false;
				}
			}
			if (isAdd == true) {
				$scope.subGrid.sonlist.push({
					id:'',
					paymentTime: '',
					operateCompanyBankInfoId : row.id,
					vid: row.vid,
					vyhzhmc: row.vyhzhmc,
					vkhh: row.vkhh,
					vyhzh: row.vyhzh,
					paymentAmount:0.00,
					accountType: row.accountType,
					accountTypeTxt: row.accountType!=null &&row.accountType==0?'对公户':'个人户',
					vjylx:'运营服务→预付款'
				});
			}

		}
	}
	$scope.getDataAfterCheckbox23 = function (rowsSelected) {
		for (var i = 0; i < rowsSelected.length; i++) {
			var row = rowsSelected[i];
			var isAdd = true; // 根据现有存在，是否加新行
			for (var j = 0; j < $scope.subGrid.sonlist.length; j++) {
				if ($scope.subGrid.sonlist[j].vid == row.vid) {
					isAdd = false;
				}
			}
			if (isAdd) {
				$scope.subGrid.sonlist.push({
					id:'',
					paymentTime: '',
					operateCompanyBankInfoId: row.id,
					vid : row.vid,
					vyhzhmc: row.vyhzhmc,
					vkhh: row.vkhh,
					vyhzh: row.vyhzh,
					paymentAmount:'0',
					capitalRegisterBid:'',
					paymentVyhzhmc:'',
					paymentVkhh:'',
					paymentVyhzh:'',
					paymentTimeByClaim:'',
					paymentAmountByClaim:'',
					vjylx:'运营服务→预付款',
					accountingVgsbm:'',
					accountingVgsmc:'',
					annexFile:'0个附件',
					remark:'',
				});
			}
		}
	}
	$scope.getDataAfterCheckbox24 = function (rowsSelected) {
		for (var i = 0; i < rowsSelected.length; i++) {
			var row = rowsSelected[i];
			var isAdd = true; // 根据现有存在，是否加新行
			for (var j = 0; j < $scope.subGrid.sonlist.length; j++) {

				if ($scope.subGrid.sonlist[j].siteId == row.id) {
					isAdd = false;
				}
			}
			if (isAdd == true) {
				$scope.subGrid.sonlist.push({
					siteId: row.id,
					shopUser:'',
					shopName: '',
					countryCode : row.countryCode,
					countryName: row.countryName,
					status: 1
				});
			}
		}
	}
	$scope.getDataAfterCheckbox25 = function (rowsSelected) {
		for (var i = 0; i < rowsSelected.length; i++) {
			var row = rowsSelected[i];
			var isAdd = true; // 根据现有存在，是否加新行
			for (var j = 0; j < $scope.subGrid.sonlist.length; j++) {
				if ($scope.subGrid.sonlist[j].vid == row.vid) {
					isAdd = false;
				}
			}
			if (isAdd) {
				$scope.subGrid.sonlist.push({
					id:'',
					paymentTime: '',
					operateCompanyBankInfoId: row.id,
					vid : row.vid,
					vyhzhmc: row.vyhzhmc,
					vkhh: row.vkhh,
					vyhzh: row.vyhzh,
					paymentAmount:'0',
					capitalRegisterBid:'',
					paymentVyhzhmc:'',
					paymentVkhh:'',
					paymentVyhzh:'',
					paymentTimeByClaim:'',
					paymentAmountByClaim:'',
					vjylx:'运营服务→预付款',
					accountingVgsbm:'',
					accountingVgsmc:'',
					annexFile:'0个附件',
					remark:'',
				});
			}
		}
	}
	$scope.getDataAfterCheckbox27 = function (rowsSelected) {
		for (var i = 0; i < rowsSelected.length; i++) {
			var row = rowsSelected[i];
			var isAdd = true; // 根据现有存在，是否加新行
			for (var j = 0; j < $scope.subGrid.sonlist.length; j++) {

				if ($scope.subGrid.sonlist[j].vatNo == row.vatNo) {
					isAdd = false;
				}
			}
			if (isAdd == true) {

				$http.post('/api/inter/thrVatApply/getLastApply', {}, {params: {vatNo: row.vatNo}})
				.success(function (res) {
					if(res.code == 0) {
						var lastDateBegin = '';
						var lastDateEnd = '';
						if (res.code == 0) {
							lastDateBegin = res.data.lastDateBegin;
							lastDateEnd = res.data.lastDateEnd;
						}
						$scope.subGrid.sonlist.push({
							vgsbm: row.vgsbm,
							vgsjc: row.vgsjc,
							type: 1,
							vatNo: row.vatNo,
							countryCode: row.countryCode,
							countryName: row.countryName,
							lastDateBegin: lastDateBegin,
							lastDateEnd: lastDateEnd,
							currencyCode: row.currencyCode
						});
					}
				});
			}
		}
	}
	$scope.getDataAfterCheckbox28 = function (rowsSelected) {
		for (var i = 0; i < rowsSelected.length; i++) {
			var row = rowsSelected[i];
			var isAdd = true; // 根据现有存在，是否加新行
			for (var j = 0; j < $scope.subGrid.sonlist.length; j++) {
				if ($scope.subGrid.sonlist[j].vid == row.vid) {
					isAdd = false;
				}
			}
			if (isAdd) {
				$scope.subGrid.sonlist.push({
					id:'',
					paymentTime: '',
					companyBankInfoId: row.id,
					vid : row.vid,
					vyhzhmc: row.vyhzhmc,
					vkhh: row.vkhh,
					vyhzh: row.vyhzh,
					inCurrencyCode:'CNY',
					outCurrencyCode:'',
					outSum:'',
					inSum:''
				});
			}
		}
	}
	$scope.getDataAfterCheckbox30 = function (rowsSelected) {
		for (var i = 0; i < rowsSelected.length; i++) {
			var row = rowsSelected[i];
			var isAdd = true; // 根据现有存在，是否加新行
			for (var j = 0; j < $scope.subGrid.sonlist.length; j++) {
				if ($scope.subGrid.sonlist[j].vid == row.vid) {
					isAdd = false;
				}
			}
			if (isAdd) {
				$scope.subGrid.sonlist.push({
					partnerBankInfoVid: row.vid,
					partnerBankInfoVyhzhmc: row.vyhzhmc,
					partnerBankInfoVyhzh: row.vyhzh,
					partnerBankInfoVkhh: row.vkhh,
					currencyCodeOut: 'USD',
					currencyCodeIn: 'CNY'
				});
			}
		}
	}
	$scope.getDataAfterCheckbox31 = function (rowsSelected) {
		for (var i = 0; i < rowsSelected.length; i++) {
			var row = rowsSelected[i];
			var isAdd = true; // 根据现有存在，是否加新行
			for (var j = 0; j < $scope.subGrid.sonlist.length; j++) {
				if ($scope.subGrid.sonlist[j].paymentReturnItemId == row.paymentReturnItemId) {
					isAdd = false;
				}
			}
			if (isAdd) {
				$scope.subGrid.sonlist.push({
					paymentReturnBid: row.bid,
					vgsbm:row.vgsbm,
					vgsjc:row.vgsjc,
					depositPlatformAccountCode:row.depositPlatformAccountCode,
					vJyLx:row.vJyLx,
					statePay:0,
					accountType:row.accountType,
					vyhzh:row.vyhzh,
					vyhzhmc:row.vyhzhmc,
					zfAmount:row.zfAmount,
					exchangeRate:row.exchangeRate,
					serviceCharge:row.serviceCharge,
					thCurrencyCode:row.thCurrencyCode,
					thAmount:row.thAmount,
					paymentReturnItemId:row.paymentReturnItemId,
					vkhh:row.vkhh,
					vlhh:row.vlhh,
				});
			}
		}
	}
	$scope.getDataAfterCheckbox32 = function (rowsSelected) {
		for (var i = 0; i < rowsSelected.length; i++) {
			var row = rowsSelected[i];
			$scope.subGrid.sonlist.push({
				bidLogsticsOrder: row.bidLogsticsOrder,
				stateShenbao: row.stateShenbao,
				cbbId: row.id,
				vgsbm: row.vgsbm,
				vgsjc: row.vgsjc
			});
		}
	}
	$scope.getDataAfterCheckbox33 = function (rowsSelected) {
		for (var i = 0; i < rowsSelected.length; i++) {
			var row = rowsSelected[i];
			$scope.subGrid.sonlist.push({
				id: '',
				platformName: row.platformName,
				depositPlatformCode: row.code,
				name: row.name,
				vname: row.vname,
				remark: row.remark,
				explain: '',
				currencyCode: '',
				amount: ''
			});
		}
	}
	$scope.getDataAfterCheckbox34 = function (rowsSelected) {//万里汇预付款入账单
		var domForm = $('#' + window.formObj.c.id_form);
		for (var i = 0; i < rowsSelected.length; i++) {
			var row = rowsSelected[i];
			row.itemId = "";
			row.reconciliationItemId = row.id;
			var exchangeRate = 0;
			var recordAmountGuiji = parseFloat(row.recordAmountGuiji);//记录归集金额
			var jyCurrencyCode = row.jyCurrencyCode;//币种
			if(jyCurrencyCode=="GBP"){
				exchangeRate = parseFloat(domForm.find('input[name="exchangeRateByGbp"]').val());
			}else if(jyCurrencyCode=="USD"){
				exchangeRate = parseFloat(domForm.find('input[name="exchangeRateByUsd"]').val());
			}else if(jyCurrencyCode=="EUR"){
				exchangeRate = parseFloat(domForm.find('input[name="exchangeRateByEur"]').val());
			}
			//计算入账金额（CNY） = 记录归集金额*对应币种的计算汇率*0.998*0.98
			var recordedAmount = recordAmountGuiji*exchangeRate*0.998*0.98;
			row.recordedAmount = recordedAmount.toFixed(2);
			console.log('row',row);
			$scope.subGrid.sonlist.push(row);
		}
		var recordedTotal = parseFloat(domForm.find('input[name="recordedTotal"]').val());//总入账金额（CNY）
		var recordedOperations = 0;//运营入账金额（CNY） = 子表入账金额之和
		for(var i=0;i<$scope.subGrid.sonlist.length; i++){
			var recordedAmountByItem = parseFloat($scope.subGrid.sonlist[i].recordedAmount);
			recordedOperations = recordedOperations+recordedAmountByItem;
		}
		var recordedFinance = recordedTotal - recordedOperations;//财务入账金额（CNY） = 总入账金额（CNY）-运营入账金额（CNY）
		$scope.valueMap['recordedOperations'] = recordedOperations.toFixed(2);
		$scope.valueMap['recordedFinance'] = recordedFinance.toFixed(2);
	}
	$scope.getDataAfterCheckbox35 = function (rowsSelected) {
	    var domForm = $('#' + window.formObj.c.id_form);
		var payType = domForm.find('select[name="payType"]').val(); // 付款类型
		var exchangeRate = parseFloat(domForm.find('input[name="exchangeRate"]').val()); // 计算汇率

		for (var i = 0; i < rowsSelected.length; i++) {
			var row = rowsSelected[i];
			var isAdd = true; // 根据现有存在，是否加新行
			for (var j = 0; j < $scope.subGrid.sonlist.length; j++) {
				if ($scope.subGrid.sonlist[j].relativeId == row.id) {
					isAdd = false;
				}
			}
			if (isAdd) {
				var fee = 0;
				var remark = '';
				if (payType == 1) {
					remark = '透明计划账单编码：' + (row.platformBid ? row.platformBid : '');
				} else if (payType == 2) {
					remark = 'VAT号：' + (row.vatNo ? row.vatNo : '');
				}
				
				$scope.subGrid.sonlist.push({
					relativeId: row.id,
					vgsbm: row.vgsbm,
					vgsjc: row.vgsjc,
					vyhzhmc: row.vyhzhmc,
					vyhzh: row.vyhzh,
					vkhh: row.vkhh,
					vaba: row.vaba,
					swiftCode: row.swiftCode,
					amount: row.billingAmount,
					currencyCode: row.currencyCode,
					remark: remark,
					vjylx: payType == 1 ? '运营服务→透明计划标签费用' : (payType == 2 ? '运营服务→VAT税费' : ''),
					fee: fee,
					amountCny: exchangeRate ? Math.round((row.billingAmount + fee) * exchangeRate * 100) / 100 : 0
				});
			}
		}
		// 计算付款外币总金额、付款CNY总金额
		if(exchangeRate) {
			var amountTotalLocal = 0;
			var amountTotalCny = 0;
			for (var i = 0; i < $scope.subGrid.sonlist.length; i++) {
				var amount = parseFloat($scope.subGrid.sonlist[i]['amount']);
				if(amount) {
					amountTotalLocal = amountTotalLocal + amount;
					amountTotalCny = amountTotalCny + Math.round(amount * exchangeRate * 100) / 100;
				}
			}
			$scope.valueMap['amountTotalLocal'] = amountTotalLocal;
			$scope.valueMap['amountTotalCny'] = Math.round(amountTotalCny * 100) / 100;
		}
	}
	$scope.getDataAfterCheckbox36 = function (rowsSelected) {
		for (var i = 0; i < rowsSelected.length; i++) {
			var row = rowsSelected[i];
			var isAdd = true; // 根据现有存在，是否加新行
			for (var j = 0; j < $scope.subGrid.sonlist.length; j++) {
				if ($scope.subGrid.sonlist[j].wanliPrepaymentPoolingId == row.id) {
					isAdd = false;
				}
			}
			if (isAdd) {
				$scope.subGrid.sonlist.push({
					wanliPrepaymentPoolingId: row.id,
					fkMid: row.fkMid,
					payerAccountNo: row.payerAccountNo,
					payerName: row.payerName,
					fkVyhsx: row.fkVyhsx,
					skMid: row.skMid,
					beneficiaryAccountNo: row.beneficiaryAccountNo,
					beneficiaryName: row.beneficiaryName,
					skVyhsx: row.skVyhsx,
					transactionType: row.transactionType,
					originalTransactionAmount: row.originalTransactionAmount,
					jyCurrencyCode: row.jyCurrencyCode,
					extTransactionId: row.extTransactionId,
					transactionId: row.transactionId,
					transactionTime: row.transactionTime,
					transactionStatus: row.transactionStatus,
					description: row.description,
					vgsbm: row.vgsbm,
					vgsjc: row.vgsjc,
					recordAmountGuiji: row.originalTransactionAmount
				});
			}
		}
		
		// 根据币种计算归集总金额
		var amountGuijiGbp = 0;
		var amountGuijiUsd = 0;
		var amountGuijiEur = 0;
		for (var i = 0; i < $scope.subGrid.sonlist.length; i++) {
			var jyCurrencyCode = $scope.subGrid.sonlist[i].jyCurrencyCode;
			var recordAmountGuiji = $scope.subGrid.sonlist[i].recordAmountGuiji
			if(jyCurrencyCode == 'GBP') {
				amountGuijiGbp = amountGuijiGbp + recordAmountGuiji;
			} else if(jyCurrencyCode == 'USD') {
				amountGuijiUsd = amountGuijiUsd + recordAmountGuiji;
			} else if(jyCurrencyCode == 'EUR') {
				amountGuijiEur = amountGuijiEur + recordAmountGuiji;
			}
		}
		$scope.valueMap['amountGuijiGbp'] = amountGuijiGbp;
		$scope.valueMap['amountGuijiUsd'] = amountGuijiUsd;
		$scope.valueMap['amountGuijiEur'] = amountGuijiEur;
	}
	$scope.getDataAfterCheckbox37 = function (rowsSelected) {//财务工资小计部门维护
		for (var i = 0; i < rowsSelected.length; i++) {
			var row = rowsSelected[i];
			var isAdd = true; // 根据现有存在，是否加新行
			for (var j = 0; j < $scope.subGrid.sonlist.length; j++) {
				if ($scope.subGrid.sonlist[j].orgid == row.orgid) {
					isAdd = false;
				}
			}
			if (isAdd) {
				$scope.subGrid.sonlist.push({
					id: "",
					orgid: row.orgid,
					orgName: row.orgNameNew,
					orgNameNew: row.orgNameNew
				});
			}
		}
	}
	$scope.getDataAfterCheckbox38 = function (rowsSelected) {
		var t = this;
		for (var i = 0; i < rowsSelected.length; i++) {
			var row = rowsSelected[i];
			var isAdd = true; // 根据现有存在，是否加新行
			for (var j = 0; j < $scope.subGrid.sonlist.length; j++) {
				if ($scope.subGrid.sonlist[j].productCode == row.productCode) {
					isAdd = false;
				}
			}
			if (isAdd) {
				$scope.subGrid.sonlist.push({
					allocateDetailId: row.id,
            		bidAllocate: row.bidAllocate,
            		allocateType: row.typeAllocate,
            		vgsbmFrom: row.vgsbmFrom,
            		vgsjcFrom: row.vgsjcFrom,
            		vgsbmTo: row.vgsbmTo,
            		vgsjcTo: row.vgsjcTo,
					productCode: row.productCode,
					productName: row.productName,
					allocateNum: row.allocateNum,
					distributedNum: row.distributedNum,
					canceledNum: row.canceledNum
				});
			}
		}
	}
	$scope.getDataAfterCheckbox39 = function (rowsSelected) {
		var t = this;
		for (var i = 0; i < rowsSelected.length; i++) {
			var row = rowsSelected[i];
			var isAdd = true; // 根据现有存在，是否加新行
			for (var j = 0; j < $scope.subGrid.sonlist.length; j++) {
				if ($scope.subGrid.sonlist[j].productCode == row.productCode) {
					isAdd = false;
				}
			}
			if (isAdd) {
				$scope.subGrid.sonlist.push({
					allocateDetailId: row.id,
					bidAllocate: row.bidAllocate,
					vgsbmFrom: row.vgsbmFrom,
					vgsjcFrom: row.vgsjcFrom,
					vgsbmTo: row.vgsbmTo,
					vgsjcTo: row.vgsjcTo,
					productCode: row.productCode,
					productName: row.productName,
					depotId: row.depotId,
					depotName: row.depotName,
					allocateNum: row.allocateNum,
					allocateSinglePrice: row.allocateSinglePrice,
					allocateTotalPrice: row.allocateTotalPrice,
					distributedNum: row.distributedNum,
					distributedTotalPrice: row.distributedTotalPrice,
					canceledNum: row.canceledNum,
	            	singlePrice: (row.typeAllocate == 1 ? row.allocateSinglePrice : row.purchaseSinglePrice)
				});
			}
		}
	}
	$scope.getDataAfterCheckbox43 = function (rowsSelected) {
		var t = this;
		for (var i = 0; i < rowsSelected.length; i++) {
			var row = rowsSelected[i];
			var isAdd = true; // 根据现有存在，是否加新行
			for (var j = 0; j < $scope.subGrid.sonlist.length; j++) {
				if ($scope.subGrid.sonlist[j].vremark == row.vReMark) {
					isAdd = false;
				}
			}
			if (isAdd) {
				$scope.subGrid.sonlist.push({
					id: row.id,
					vid: row.vName,
					vname: row.vAccountName,
					vaccountname: row.vAccount,
					vremark: row.vReMark
				});
			}
		}
	}
}]);